//
//  WealthViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/27.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "WealthViewController.h"
#import "OperateListViewController.h"
#import "MethodsController.h"
#import "NoticeView.h"
#import "SafeCenterViewController.h"
#import "RuleViewController.h"

@interface WealthViewController ()<UITextFieldDelegate>{
    UILabel *titleLabel;
    UILabel *noteLabel;
}

@property (nonatomic, strong) UIView *moveLine;
@property (nonatomic, strong) UILabel *xiabi;
@property (nonatomic, strong) UILabel *balance;

@property (nonatomic, strong) UIImageView   *weixin;
@property (nonatomic, strong) UIImageView   *zhifubao;
@property (nonatomic, strong) UILabel       *weixinLabel;
@property (nonatomic, strong) UILabel       *zhifubaoLabel;
@property (nonatomic, strong) UIImageView   *weixinImg;
@property (nonatomic, strong) UIImageView   *zhifubaoImg;
@property (nonatomic, strong) UITextField   *tixianMoney;
@property (nonatomic, strong) UILabel       *notice;
@property (nonatomic, strong) NSString      *xiabiValue;
@property (nonatomic, strong) NSString      *balanceValue;
@property (nonatomic, strong) NSString      *weiXinAccount;
@property (nonatomic, strong) NSString      *aliPayAccount;
@property (nonatomic, strong) UIView *leftView;
@property (nonatomic, strong) UIView *rightView;
@property (nonatomic, strong) NoticeView *noticeView;

@property (nonatomic, assign) NSInteger isCoin;
@property (nonatomic, assign) NSInteger drawtype;

///收取服务费label
@property (nonatomic,strong)  UILabel  * serveFeeLabel;
///费率
@property (nonatomic,assign)  NSInteger    feeRate;
///虾币转余额的数量
@property (nonatomic,assign)  NSInteger    xiaBiNum;
///textField上的虾币提现数
@property (nonatomic,assign)  NSInteger    xiaBiStr;

@end

@implementation WealthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _drawtype = 1;
    _isCoin = 1;
    self.title = @"财富";
    self.view.backgroundColor = [UIColor whiteColor];

    UIButton *listBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, ScreenX375(76), ScreenX375(21))];
    [listBtn setTitle:@"财富记录" forState:UIControlStateNormal];
    [listBtn setTitleColor:REXADECIMALCOLOR(@"#000000") forState:UIControlStateNormal];
    listBtn.titleLabel.font = Kfont(16);
    [listBtn addTarget:self action:@selector(list) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:listBtn];
    
    UIButton *saveBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49), SCREEN_WIDTH, ScreenX375(49))];
    [saveBtn setTitle:@"提现" forState:UIControlStateNormal];
    [saveBtn setBackgroundImage:[UIImage imageNamed:@"按钮背景"] forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveBtn.titleLabel.font = Kfont(18);
        [saveBtn addTarget:self action:@selector(NoticeView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:saveBtn];
    
    [self setTopUI];
    [self setUI];
    [self getRateData];
    [self getData];
    [self setNoticeView];
}

-(void)viewWillDisappear:(BOOL)animated{
    [_noticeView removeFromSuperview];
    _noticeView = nil;
}

- (void)list {
    OperateListViewController *vc = [[OperateListViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)getRateData
{
    //NSDictionary *parameter = @{@"userId":kNSUDefaultReadKey(@"userId"),@"type":@(typeNum)};
    NSString *urlStr = [NSString stringWithFormat:@"%@api/rule",REQUESTHEADER];
    [HttpManager postHttpRequestByGet:urlStr andParameter:nil success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            self.xiaBiNum = [successResponse[@"data"][@"coinChange"] integerValue];
            self.feeRate = [successResponse[@"data"][@"balanceRate"] integerValue];
            NSString *aliPay = [NSString stringWithFormat:@"%@",successResponse[@"data"][@"aliPay"]];
            NSString *weChatPay = [NSString stringWithFormat:@"%@", successResponse[@"data"][@"weChatPay"]];
            BOOL isAliPay;
            BOOL isWeChatPay;
            if ([aliPay isEqualToString:@"1"]) {
                isAliPay = YES;
            }else{
                isAliPay = NO;
            }
            if ([weChatPay isEqualToString:@"1"]) {
                isWeChatPay = YES;
            }else{
                isWeChatPay = NO;
            }
            if (isAliPay^isWeChatPay  ) {
                if (isAliPay == YES) {
                    self->_zhifubao.frame = CGRectMake((SCREEN_WIDTH - ScreenX375(80))/2, ScreenX375(353), ScreenX375(80), ScreenX375(80));
                    self->_weixin.hidden = YES;
                    [self drawAliPay];
                }else{
                    self->_weixin.frame = CGRectMake((SCREEN_WIDTH - ScreenX375(80))/2, ScreenX375(353), ScreenX375(80), ScreenX375(80));
                    self->_zhifubao.hidden = YES;
                    [self drawWX];
                }
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)setNoticeView{
    if (_noticeView == nil) {
        _noticeView = [[NoticeView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [kKeyWindow addSubview:_noticeView];
        __weak __typeof(self) weakSelf = self;
        _noticeView.hiddenClick = ^{
            [UIView animateWithDuration:0.3 animations:^{
                weakSelf.noticeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
            }];
        };
        
        _noticeView.doneClick = ^{
            SafeCenterViewController *vc = [[SafeCenterViewController alloc] init];
            
            [weakSelf.navigationController pushViewController:vc animated:YES];
            [UIView animateWithDuration:0.3 animations:^{
                weakSelf.noticeView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
            }];
        };
    }
}

-(void)NoticeView
{
    if (_isCoin == 1) {
        if (self.xiaBiStr < self.xiaBiNum) {
            NSString *string = [NSString stringWithFormat:@"虾币提现不得少于%ld",self.xiaBiNum];
            [HttpManager showNoteMsg:string];
            return;
        }
        if ([_tixianMoney.text doubleValue] > [_xiabiValue doubleValue]) {
            [HttpManager showNoteMsg:@"提现虾币不能超过虾币总数"];
        }else if (_tixianMoney.text.length == 0){
            [HttpManager showNoteMsg:@"请输入提现虾币数目"];
        }else{
            if (_drawtype == 1) {
                if ([_weiXinAccount isEqualToString:@"-1"] || [_weiXinAccount class] == [NSNull class]) {
                    [self.noticeView setNotice:@"您还没有绑定微信账号"];
                    [UIView animateWithDuration:0.3 animations:^{
                        self.noticeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                    }];
                }else{
                    [self drawCash];
                }
            }else{
                if ([_aliPayAccount class] == [NSNull class]) {
                    [self.noticeView setNotice:@"您还没有绑定支付宝账号"];
                    [UIView animateWithDuration:0.3 animations:^{
                        self.noticeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                    }];
                }else if([_aliPayAccount isEqualToString:@"-1"]){
                    [self.noticeView setNotice:@"您还没有绑定支付宝账号"];
                    [UIView animateWithDuration:0.3 animations:^{
                        self.noticeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                    }];
                }else{
                    [self drawCash];
                }
            }
        }
    }else{
        if ([_tixianMoney.text doubleValue] < 10) {
            [HttpManager showNoteMsg:@"提现金额不得少于10元"];
            return;
        }
        if ([_tixianMoney.text doubleValue] > [_balanceValue doubleValue]) {
            [HttpManager showNoteMsg:@"提现金额不能超过余额"];
        }else if (_tixianMoney.text.length == 0){
            [HttpManager showNoteMsg:@"请输入提现金额"];
        }else{
            if (_drawtype == 1) {
                if ([_weiXinAccount isEqualToString:@"-1"] || [_weiXinAccount class] == [NSNull class]) {
                    [self.noticeView setNotice:@"您还没有绑定微信账号"];
                    [UIView animateWithDuration:0.3 animations:^{
                        self.noticeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                    }];
                }else{
                    [self drawCash];
                }
            }else{
                if ([_aliPayAccount class] == [NSNull class]) {
                    [self.noticeView setNotice:@"您还没有绑定支付宝账号"];
                    [UIView animateWithDuration:0.3 animations:^{
                        self.noticeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                    }];
                }else if([_aliPayAccount isEqualToString:@"-1"]){
                    [self.noticeView setNotice:@"您还没有绑定支付宝账号"];
                    [UIView animateWithDuration:0.3 animations:^{
                        self.noticeView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                    }];
                }else{
                    [self drawCash];
                }
            }
        }
    }
}

- (void)setTopUI {
    UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(17), ScreenX375(328), ScreenX375(95))];
    baseView.backgroundColor = [UIColor whiteColor];
    baseView.layer.cornerRadius = ScreenX375(6);
    baseView.clipsToBounds = YES;
    
    _leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenX375(328)/2, ScreenX375(95))];
    _leftView.backgroundColor = REXADECIMALCOLOR(@"#FFEEF2");
    _leftView.tag = 100;
    
    UILabel *titleLabel1 = [[UILabel alloc] initWithFrame:CGRectMake((ScreenX375(164)-ScreenX375(56))/2, ScreenX375(23), ScreenX375(56), ScreenX375(20))];
    titleLabel1.tag = 1000;
    titleLabel1.text = @"虾币(枚)";
    titleLabel1.textColor = REXADECIMALCOLOR(@"#f21934");
    titleLabel1.textAlignment = NSTextAlignmentCenter;
    titleLabel1.font = Kfont(14);
    [_leftView addSubview:titleLabel1];
    
    if (!_xiabi) {
        _xiabi = [[UILabel alloc] initWithFrame:CGRectMake((ScreenX375(164)-ScreenX375(100))/2,ScreenX375(42),ScreenX375(100),ScreenX375(28))];
        _xiabi.text = _xiabiValue;
        _xiabi.textAlignment = NSTextAlignmentCenter;
        _xiabi.font = Kfont(20);
        _xiabi.textColor = REXADECIMALCOLOR(@"#f21934");
        [_leftView addSubview:_xiabi];
    }
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectType:)];
    [_leftView addGestureRecognizer:tap1];
    [baseView addSubview:_leftView];
    
    _rightView = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(328)/2, 0, ScreenX375(328)/2, ScreenX375(95))];
    _rightView.backgroundColor = REXADECIMALCOLOR(@"#f4f4f4");
    _rightView.tag = 101;
    
    UILabel *titleLabel2 = [[UILabel alloc] initWithFrame:CGRectMake((ScreenX375(164)-ScreenX375(56))/2, ScreenX375(23), ScreenX375(56), ScreenX375(20))];
    titleLabel2.tag = 1001;
    titleLabel2.text = @"余额(元)";
    titleLabel2.textAlignment = NSTextAlignmentCenter;
    titleLabel2.font = Kfont(14);
    [_rightView addSubview:titleLabel2];
    
    if (!_balance) {
        _balance = [[UILabel alloc] initWithFrame:CGRectMake((ScreenX375(164)-ScreenX375(100))/2,ScreenX375(42),ScreenX375(100),ScreenX375(28))];
        _balance.text = _balanceValue;
        _balance.textAlignment = NSTextAlignmentCenter;
        _balance.font = Kfont(20);
        [_rightView addSubview:_balance];
    }
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectType:)];
    [_rightView addGestureRecognizer:tap2];
    [baseView addSubview:_rightView];
    
    [self.view addSubview:baseView];
    
    
    self.moveLine = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(62),ScreenX375(71), ScreenX375(34), ScreenX375(2))];
    self.moveLine.layer.cornerRadius = ScreenX375(1.5);
    self.moveLine.clipsToBounds = YES;
    self.moveLine.backgroundColor = REXADECIMALCOLOR(@"#f21934");
    [baseView addSubview:self.moveLine];
}

- (void)select:(UIButton *)button {
    if (button.tag == 100) {
        titleLabel.text = @"余额提现";
        noteLabel.text = @"最高可提现268元";
        [UIView animateWithDuration:0.3 animations:^{
            self.moveLine.frame = CGRectMake(((SCREEN_WIDTH - ScreenX375(48)) / 2 - ScreenX375(32)) / 2, ScreenX375(74), ScreenX375(32), ScreenX375(3));
        }];
    }else {
        titleLabel.text = @"虾币提现";
        noteLabel.text = @"最高可提现36元";
        [UIView animateWithDuration:0.3 animations:^{
            self.moveLine.frame = CGRectMake(((SCREEN_WIDTH - ScreenX375(48)) / 2 - ScreenX375(32)) / 2 + (SCREEN_WIDTH - ScreenX375(48)) / 2, ScreenX375(74), ScreenX375(32), ScreenX375(3));
        }];
    }
}

- (void)hidden {
    [self.view endEditing:YES];
}

-(void)setUI{
    UILabel *sym = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(196), ScreenX375(14), ScreenX375(20))];
    sym.text = @"￥";
    sym.font = Kfont(14);
    sym.textColor = [UIColor blackColor];
    [self.view addSubview:sym];
    
    if(!_tixianMoney){
        _tixianMoney = [[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(48), ScreenX375(192), ScreenX375(200), ScreenX375(23))];
        _tixianMoney.delegate = self;
        _tixianMoney.font = Kfont(20);
        [self.view addSubview:_tixianMoney];
        [_tixianMoney addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    }
    
    if (!_notice) {
        _notice = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(222), ScreenX375(201), ScreenX375(130), ScreenX375(12))];
        _notice.text = @"最多可提现268元";
        _notice.textAlignment = NSTextAlignmentRight;
        _notice.font = Kfont(12);
        _notice.textColor = REXADECIMALCOLOR(@"#888888");
        [self.view addSubview:_notice];
    }
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(226), ScreenX375(327), ScreenX375(1))];
    line.backgroundColor = LineColor;
    [self.view addSubview:line];
    
    self.serveFeeLabel = [[UILabel alloc] init];
    self.serveFeeLabel.frame = CGRectMake(ScreenX375(24), ScreenX375(232), ScreenX375(327), ScreenX375(36));
    self.serveFeeLabel.textColor = UIColorFromRGB(@"#4a90e2", 1);
    self.serveFeeLabel.font = Kfont(12);
    self.serveFeeLabel.numberOfLines = 0;
    [self.view addSubview:self.serveFeeLabel];
    
    UILabel *label =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(24), ScreenX375(298), ScreenX375(150), ScreenX375(25))];
    label.text = @"选择提现方式";
    label.font = Kfont(18);
    label.textColor = REXADECIMALCOLOR(@"#888888");
    label.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:label];
    
    _weixin = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(80), ScreenX375(353), ScreenX375(80), ScreenX375(80))];
    _weixin.layer.cornerRadius = ScreenX375(6);
    _weixin.image = [UIImage imageNamed:@"组55"];
    _weixin.tag = 102;
    _weixin.userInteractionEnabled = YES;
    
    _weixinLabel =[[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(10), ScreenX375(50), ScreenX375(14))];
    _weixinLabel.text = @"微信";
    _weixinLabel.textColor = REXADECIMALCOLOR(@"#f21934");
    _weixinLabel.font = Kfont(14);
    _weixinLabel.textAlignment = NSTextAlignmentCenter;
    [_weixin addSubview:_weixinLabel];
    
    _weixinImg = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(20), ScreenX375(30), ScreenX375(40), ScreenX375(40))];
    _weixinImg.image = [UIImage imageNamed:@"矢量智能对象"];
    [_weixin addSubview: _weixinImg];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMethod:)];
    [_weixin addGestureRecognizer:tap3];
    [self.view addSubview:_weixin];
    
    _zhifubao = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(215), ScreenX375(353), ScreenX375(80), ScreenX375(80))];
    _zhifubao.layer.cornerRadius = ScreenX375(6);
    _zhifubao.layer.borderWidth = 1.0;
    _zhifubao.layer.borderColor = REXADECIMALCOLOR(@"#bbbbbb").CGColor;
    _zhifubao.tag = 103;
    _zhifubao.userInteractionEnabled = YES;
    
    _zhifubaoLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(15), ScreenX375(10), ScreenX375(50), ScreenX375(14))];
    _zhifubaoLabel.text = @"支付宝";
    _zhifubaoLabel.font = Kfont(14);
    _zhifubaoLabel.textColor = REXADECIMALCOLOR(@"#888888");
    _zhifubaoLabel.textAlignment = NSTextAlignmentCenter;
    [_zhifubao addSubview:_zhifubaoLabel];
    
    _zhifubaoImg = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(20), ScreenX375(30), ScreenX375(40), ScreenX375(40))];
    _zhifubaoImg.image = [UIImage imageNamed:@"支付宝1"];
    [_zhifubao addSubview: _zhifubaoImg];
    
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectMethod:)];
    [_zhifubao addGestureRecognizer:tap4];
    [self.view addSubview:_zhifubao];
    
    UIButton *ruleBtn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(80)) / 2, ScreenX375(499), ScreenX375(80), ScreenX375(12))];
    [ruleBtn setTitle:@"提现规则" forState:UIControlStateNormal];
    [ruleBtn setTitleColor:REXADECIMALCOLOR(@"#888888") forState:UIControlStateNormal];
    [ruleBtn addTarget:self action:@selector(rule) forControlEvents:UIControlEventTouchUpInside];
    ruleBtn.titleLabel.font = Kfont(13);
    [self.view addSubview:ruleBtn];
    
    UIButton *methodBtn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - ScreenX375(80)) / 2, ScreenX375(520), ScreenX375(80), ScreenX375(12))];
    [methodBtn setTitle:@"赚币方法" forState:UIControlStateNormal];
    [methodBtn setTitleColor:REXADECIMALCOLOR(@"#888888") forState:UIControlStateNormal];
    [methodBtn addTarget:self action:@selector(method) forControlEvents:UIControlEventTouchUpInside];
    methodBtn.titleLabel.font = Kfont(13);
    [self.view addSubview:methodBtn];
}

- (void)sure {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)selectType:(UITapGestureRecognizer *)gesture{
    UIView *targetview = gesture.view;
    if (targetview.tag == 101) {
        _leftView.backgroundColor = REXADECIMALCOLOR(@"#f4f4f4");
        _rightView.backgroundColor = REXADECIMALCOLOR(@"#FFEEF2");
        UILabel * titleLabel2 = [self.view viewWithTag:1001];
        titleLabel2.textColor = REXADECIMALCOLOR(@"#f21934");
        UILabel * titleLabel1 = [self.view viewWithTag:1000];
        titleLabel1.textColor = REXADECIMALCOLOR(@"#212121");
        _xiabi.textColor = REXADECIMALCOLOR(@"#212121");
        _balance.textColor = REXADECIMALCOLOR(@"#f21934");
        [UIView animateWithDuration:0.4 animations:^{
            self.moveLine.frame = CGRectMake(ScreenX375(228),ScreenX375(71), ScreenX375(34), ScreenX375(2));
        }];
        _isCoin = 0;
        [self getData];
        if (self.tixianMoney.text.length != 0) {
            self.tixianMoney.text = @"";
        }
    }else if(targetview.tag == 100){
        _leftView.backgroundColor = REXADECIMALCOLOR(@"#FFEEF2");
        _rightView.backgroundColor = REXADECIMALCOLOR(@"#f4f4f4");
        UILabel * titleLabel2 = [self.view viewWithTag:1001];
        titleLabel2.textColor = REXADECIMALCOLOR(@"#212121");
        UILabel * titleLabel1 = [self.view viewWithTag:1000];
        titleLabel1.textColor = REXADECIMALCOLOR(@"#f21934");
        _xiabi.textColor = REXADECIMALCOLOR(@"#f21934");
        _balance.textColor = REXADECIMALCOLOR(@"#212121");
        [UIView animateWithDuration:0.4 animations:^{
            self.moveLine.frame = CGRectMake(ScreenX375(62),ScreenX375(71), ScreenX375(34), ScreenX375(2));
        }];
        _isCoin = 1;
        [self getData];
        if (self.tixianMoney.text.length != 0) {
            self.tixianMoney.text = @"";
        }
    }
}

- (void)rule
{
    RuleViewController *vc = [[RuleViewController alloc] init];
    [self.navigationController pushViewController:vc animated:true];
}

-(void)method{
    MethodsController *vc = [[MethodsController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)selectMethod:(UITapGestureRecognizer *)gesture{
    UIView *targetview  = gesture.view;
    if (targetview.tag == 102) {
        [self drawWX];
    }else{
        [self drawAliPay];
    }
}

-(void)drawWX{
    _weixin.image = [UIImage imageNamed:@"组55"];
    _weixinLabel.textColor = REXADECIMALCOLOR(@"#f21934");
    _weixin.layer.borderWidth = 0;
    
    _zhifubao.layer.cornerRadius = ScreenX375(6);
    _zhifubao.layer.borderWidth = 1.0;
    _zhifubao.layer.borderColor = REXADECIMALCOLOR(@"#bbbbbb").CGColor;
    _zhifubao.image = nil;
    _zhifubaoLabel.textColor = REXADECIMALCOLOR(@"#888888");
    _drawtype = 1;
}

-(void)drawAliPay{
    _zhifubao.image = [UIImage imageNamed:@"组55"];
    _zhifubaoLabel.textColor = REXADECIMALCOLOR(@"#f21934");
    _zhifubao.layer.borderWidth = 0;
    
    _weixin.layer.cornerRadius = ScreenX375(6);
    _weixin.layer.borderWidth = 1.0;
    _weixin.layer.borderColor = REXADECIMALCOLOR(@"#bbbbbb").CGColor;
    _weixinLabel.textColor = REXADECIMALCOLOR(@"#888888");
    _weixin.image = nil;
    _drawtype = 0;
}

- (void)getData
{
    NSDictionary *parameter = @{@"id":kNSUDefaultReadKey(@"userId"),@"userId":kNSUDefaultReadKey(@"userId")};
    [HttpManager postHttpRequestByGet:[NSString stringWithFormat:@"%@api/getUserInfo",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {;
            NSString *balance = successResponse[@"data"][@"userInfo"][@"balance"];
            self.xiabiValue = [NSString stringWithFormat:@"%@",successResponse[@"data"][@"userInfo"][@"coin"]];
            self.balanceValue = [NSString stringWithFormat:@"%.2f",[balance doubleValue]];
            
            self.weiXinAccount = successResponse[@"data"][@"userInfo"][@"wxAccount"];
            self.aliPayAccount = successResponse[@"data"][@"userInfo"][@"aliAccount"];
            
            self.xiabi.text = self.xiabiValue;
            self.balance.text = self.balanceValue;
            
            if (self.isCoin == 1) {
                self.notice.text = [NSString stringWithFormat:@"%ld枚虾币 = 1元",self.xiaBiNum];
                self.tixianMoney.keyboardType = UIKeyboardTypeNumberPad;
                self.tixianMoney.placeholder = @"请输入提现的虾币数";
                self.serveFeeLabel.text = [[NSString stringWithFormat:@"平台将收取%ld",self.feeRate] stringByAppendingString:@"%的服务费"];
            }else{
                self.notice.text = [NSString stringWithFormat:@"最多可提现%@元",self.balanceValue];
                self.tixianMoney.keyboardType = UIKeyboardTypeDecimalPad;
                self.tixianMoney.placeholder = @"请输入提现金额";
                self.serveFeeLabel.text = [[NSString stringWithFormat:@"平台将收取%ld",self.feeRate] stringByAppendingString:@"%的服务费"];
            }
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)drawCash
{
    NSDictionary *parameter = @{@"userId":kNSUDefaultReadKey(@"userId"),@"type":[NSString stringWithFormat:@"%ld",_drawtype],@"price":_tixianMoney.text,@"isCoin":[NSString stringWithFormat:@"%ld",_isCoin]};
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/withdrawCash",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([status isEqualToString:@"200"]) {
            [self getData];
            [HttpManager showNoteMsg:@"提现成功"];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

- (void)textFieldDidChange:(id)sender
{
    UITextField *field = (UITextField *)sender;
    CGFloat feeRate1 = self.feeRate*0.01;
    CGFloat moneyNum;
    if (self.isCoin == 1) {
        if ([field.text integerValue] >= self.xiaBiNum) {
            NSInteger xiabiF = field.text.length;
            moneyNum = [field.text integerValue]/self.xiaBiNum+([field.text integerValue]/(int)pow(10, xiabiF-2)%10)*0.1+([field.text integerValue]/(int)pow(10, xiabiF-3)%10)*0.01;
        }else{
            moneyNum = [field.text integerValue]/self.xiaBiNum;
        }
        CGFloat feeNum = moneyNum*feeRate1;
        CGFloat realMoney = moneyNum - feeNum;
        self.xiaBiStr = [field.text integerValue];
        self.serveFeeLabel.text = [NSString stringWithFormat:@"提现金额%.2f元,额外扣除￥%.2f服务费,实际到账%.2f元",moneyNum,feeNum,realMoney];
    }else{
        CGFloat feeNum = [field.text floatValue]*feeRate1;
        CGFloat realMoney = [field.text floatValue] - feeNum;
        self.serveFeeLabel.text = [NSString stringWithFormat:@"提现金额%@元,额外扣除￥%.2f服务费,实际到账%.2f元",field.text,feeNum,realMoney];
    }
}


@end
